'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 3_use_struct_to_create_tool.py
* @Time: 2025/11/1
* @All Rights Reserve By Brtc
'''
import asyncio

from langchain_core.tools import StructuredTool
from pydantic import BaseModel, Field


class CaculatorInput(BaseModel):
    a: int = Field(description="第一个数字")
    b: int = Field(description="第二个数字")

def multiply(a:int, b:int)->int:
    """同步方法将两个数相乘"""
    print("我是同步方法")
    return a*b

async def amultiply(a:int, b:int)->int:
    """异步方法将两个数相乘"""
    print("我是异步方法")
    return a*b

calculator = StructuredTool.from_function(
    func=multiply,
    coroutine=amultiply,
    name="牛逼的计算工具",
    description="用于两个数字相乘",
    return_direct=True,
    args_schema=CaculatorInput
)


print("工具名字:", calculator.name)
print("工具描述:", calculator.description)
print("工具参数:", calculator.args)
print("是否直接返回:", calculator.return_direct)
print("直接调用:",calculator.invoke({"a":2,"b":3}))
print("异步调用:", asyncio.run(calculator.ainvoke({"a":2,"b":3})))
